package com.young.study_wagger_demo.product;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
@Service
public class ProductSerivce {
    private final ProductRepository productRepository;

    public List<Product> findAll() {
        return productRepository.findAll();
    }

    public Optional<Product> findById(Long id) {
        return productRepository.findById(id);
    }

    public Product save(Product stock) {
        return productRepository.save(stock);
    }

    public Optional<Long> deleteById(Long id) {
        if(productRepository.existsById(id)) {
            productRepository.deleteById(id);
            return Optional.of(id);
        }
        return Optional.empty();
    }

    public void doSomething(Optional<Product> p) {

    }

}
